<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <script src="js/base.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            /* 背景图设置：覆盖全屏、居中显示、固定不滚动 */
            background-image: url("images/beijingtu.jpg"); /* 需替换为实际背景图路径 */
            background-size: cover;
            background-position: center;
            background-attachment: fixed;
            background-repeat: no-repeat;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
            /* 半透明黑色叠加层，提升文字可读性 */
            position: relative;
        }

        /* 背景图叠加层 */
        body::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5); /* 黑色半透明，可调整透明度 */
            z-index: -1; /* 确保叠加层在背景图之上、内容之下 */
        }

        .login-container {
            background-color: rgba(255, 255, 255, 0.95); /* 表单容器半透明白色，减少背景干扰 */
            width: 100%;
            max-width: 400px;
            padding: 30px 40px;
            border-radius: 12px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
            z-index: 1; /* 确保表单在叠加层之上 */
        }
        h1 {
            color: #1a73e8;
            text-align: center;
            margin-bottom: 30px;
            font-weight: 600;
            font-size: 28px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            color: #5f6368;
            font-size: 14px;
        }

        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #dadce0;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.2s ease;
            background-color: white; /* 输入框纯白背景，提升输入清晰度 */
        }

        input[type="text"]:focus,
        input[type="password"]:focus {
            outline: none;
            border-color: #1a73e8;
            box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
        }

        .button-group {
            display: flex;
            gap: 10px;
            margin-top: 15px;
        }

        button {
            flex: 1;
            padding: 12px;
            background-color: #1a73e8;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        button:hover {
            background-color: #0d66d0;
            transform: translateY(-2px);
        }

        button:nth-child(2) {
            background-color: #34a853;
        }

        button:nth-child(2):hover {
            background-color: #2d8643;
        }

        .divider {
            display: flex;
            align-items: center;
            margin: 20px 0;
        }

        .divider::before, .divider::after {
            content: "";
            flex: 1;
            height: 1px;
            background-color: #dadce0;
        }

        .divider span {
            padding: 0 10px;
            color: #5f6368;
            font-size: 13px;
        }
    </style>
</head>
<body>
<div class="login-container">
    <h1>用户登录</h1>

    <div class="form-group">
        <label for="username">用户名</label>
        <input type="text" id="username" placeholder="请输入用户名"/>
    </div>

    <div class="form-group">
        <label for="password">密码</label>
        <input type="password" id="password" placeholder="请输入密码"/>
    </div>

    <div class="button-group">
        <button onclick="onSignInClick();">登录</button>
        <button onclick="goSignUpClick();">注册</button>
    </div>

</div>

<script>
        function onSignInClick() {
            let url = "http://localhost:8080/user/signIn";
            let method = "post";
            let json = {
                username: document.getElementById('username').value,
                password: document.getElementById('password').value
            };

            // 简单验证
            if (!json.username || !json.password) {
                alert("请输入用户名和密码");
                return;
            }

            $.rest(url, method, json, function (r) {
                if (r.code == 200) {
                    let teacher = r.data;
                    localStorage.setItem("tid", teacher.id);
                    localStorage.setItem("tname", teacher.name);
                    window.location.href = "teacherIndex.html";
                } else if (r.code == 201) {
                    let student = r.data;
                    localStorage.setItem("sid", student.id);
                    localStorage.setItem("sname", student.name);
                    window.location.href = "studentIndex.html";
                } else {
                    alert("登录信息有误");
                }
            });
        }

        function goSignUpClick() {
            window.location.href = "signUp.html";
        }
    </script>
</body>
</html>